Skip to content

fix: create internal application when plugin adds Messenger after init#998

Merged
eternal-flame-AD merged 3 commits into
gotify:masterfrom
TowyTowy:fix/plugin-messenger-application-id
Jul 16, 2026
Merged

fix: create internal application when plugin adds Messenger after init#998
eternal-flame-AD merged 3 commits into
gotify:masterfrom
TowyTowy:fix/plugin-messenger-application-id

Conversation

@TowyTowy

Copy link
Copy Markdown
Contributor

Fixes #653

Problem

When a plugin implements the plugin.Messenger interface after it has already been initialized for a user, its PluginConf already exists with no associated internal application (ApplicationID == 0). On the next startup, initializeSingleUserPlugin reuses that conf and wires the message handler with ApplicationID: 0, so every message the plugin sends is stored with application_id = 0. Those messages are orphaned: they don't appear after a page refresh and can't be deleted (DELETE returns 404). This matches the maintainer's diagnosis in #653.

Fix

On initialization, if a plugin supports Messenger but has no internal application yet (ApplicationID == 0), create one and persist it on the conf — mirroring what already happens for plugins that support Messenger from the start. The internal-application creation is extracted into a shared helper. The back-fill is idempotent: plugins that already have an application are untouched.

Testing

Added TestNewManager_MessengerAddedAfterInit_createsApplication, which seeds a conf without an application and asserts an internal application is created after re-initialization with a Messenger-capable plugin. It fails on master (ApplicationID stays 0) and passes with this change. go test ./plugin/..., gofmt/gofumpt, and go vet are clean.


Disclosure: this change was prepared with assistance from Claude (an AI tool); all code was reviewed and verified by me.

When a plugin gains the Messenger capability after it was first
initialized for a user, its plugin conf already exists without an
associated internal application (ApplicationID == 0). Messages sent by
the plugin were then stored with application_id = 0, orphaning them:
they disappeared on reload and could not be deleted (gotify#653).

Back-fill the internal application during initialization when a
Messenger plugin has none yet, mirroring the creation already done for
plugins that support Messenger from the start.

Fixes gotify#653

Co-Authored-By: Claude <noreply@anthropic.com>
@TowyTowy TowyTowy requested a review from a team as a code owner July 12, 2026 20:38
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 74.48%. Comparing base (e2b6a2e) to head (a9cec79).

Files with missing lines Patch % Lines
plugin/manager.go 95.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #998      +/-   ##
==========================================
+ Coverage   74.32%   74.48%   +0.16%     
==========================================
  Files          66       66              
  Lines        3462     3476      +14     
==========================================
+ Hits         2573     2589      +16     
+ Misses        689      688       -1     
+ Partials      200      199       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@eternal-flame-AD eternal-flame-AD left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, just one thing: can you add a double check in messagehandler.go to do a final check that the application ID is not zero? thanks. I wish we have foreign keys working.

Add a final safety net in redirectToChannel.SendMessage that refuses a
message when ApplicationID == 0, so it can never be stored as an orphaned
message (application_id = 0, not shown, not deletable). Requested in review.

Cover the previously untested error branches around internal-application
back-fill (create/update failures) so patch coverage no longer regresses.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@TowyTowy

Copy link
Copy Markdown
Contributor Author

Done. Added the safety net in messagehandler.go: SendMessage now returns an error if ApplicationID == 0 rather than queueing a message that would be stored with application_id = 0 and orphaned. Also added tests covering it and the internal-application back-fill error paths, which should clear the codecov patch/project checks. Agreed on the foreign keys wish.

(Prepared with AI assistance, reviewed and verified by me.)

@eternal-flame-AD eternal-flame-AD added this pull request to the merge queue Jul 16, 2026
Merged via the queue into gotify:master with commit ec4e2d5 Jul 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Plugins messages not displayed upon refresh of the message page, nor can they be deleted

2 participants